package cn.com.sinux.spring.utils.image;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 图像转换的工厂类.
 *
 * @author <a href="mailto:oznyang@163.com">oznyang</a>, <a href="mailto:dxchen@wiscom.com.cn">dxchen</a>
 */
public class ImageTransformFactory {

    private static String transformClassName;
    private final static Logger logger = LoggerFactory.getLogger(ImageTransformFactory.class);

    public static void setTransformProvider(String cname) {
        transformClassName = StringUtils.trimToNull(cname);
        logger.debug("TransformProvider:{}", transformClassName);
    }

    private static ImageTransform getImageTransformFromClassName(final String className) {
        if (className == null)
            return null;

        try {
            Class clazz = Class.forName(className);
            return (ImageTransform) clazz.newInstance();
        } catch (Throwable e) {
            logger.error("Invalid provider class of image transforming.", e);
        }
        return null;
    }

    /**
     * 获取图像转换的实现类.
     *
     * @return 图像转换的实现类.
     */
    public static ImageTransform getImageTransform() {

        ImageTransform imageTransform = new AwtImageTransform();
        return imageTransform;
    }
}
